﻿using Accountant.DataModel;
using NUnit.Framework;
using FluentAssertions;

namespace UnitTests
{
  [TestFixture]
  public class UnboundIntegrity
  {
    [SetUp]
    public void SetUp()
    {
      AccountantContext.CleanUnboundContext();
    }
    [Test]
    public void UnboundIsBoundToSpecialContext()
    {
      new Account().Context.ToString().Should().Be("Unbound");
    }
    [Test]
    public void UnboundContextDesntReferenceItsObjects()
    {
      var account = new Account();
      account.Context.Accounts.Should().BeEmpty();
    }
    [Test]
    public void ObjectsDeletedFromOldContext()
    {
      new AccountantContext().Accounts.Add(new Account());
      AccountantContext.Unbound.Accounts.Should().BeEmpty();
    }

    [Test]
    public void ManyToOneIntegrityWorksOnUnboundObjects()
    {
      var bse = new Account { Name = "Base" };
      var derived = new Account { Name = "Derived" };
      bse.DerivedAccounts.Add(derived);
      derived.BaseAccount.Should().BeSameAs(bse);
    }
    [Test]
    public void OneToManyIntegrityDoesnWorkOnUnboundObjects()
    {
      var bse = new Account { Name = "Base" };
      var derived = new Account { Name = "Derived" };
      derived.BaseAccount = bse;
      bse.DerivedAccounts.Should().BeEmpty();
    }
  }
}